package com.scm.biz.service._impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.scm.biz.bean.Order;
import com.scm.biz.bean.ProofingOrder;
import com.scm.biz.bean.ProofingPattern;
import com.scm.biz.dao.CustomerDao;
import com.scm.biz.dao.OrderDao;
import com.scm.biz.dao.ProofingOrderDao;
import com.scm.biz.dao.ProofingPatternDao;
import com.scm.biz.dto.MsgNoticeDto;
import com.scm.biz.enums.OrderTypeEnum;
import com.scm.biz.query.OrderQuery;
import com.scm.biz.result.OrderResult;
import com.scm.biz.service.MsgNoticeService;
import com.scm.biz.service.OrderService;
import com.scm.biz.service.OrderTaskFlowService;
import com.scm.utils.UfdmDateUtil;
/**
 * 所有订单业务层接口实现
 * @author 张乐锋
 *
 */
@Service
public class OrderServiceImpl implements OrderService {
	
	@Resource
	private OrderDao orderDao;
	@Autowired
	CustomerDao customerDao;
	@Autowired
	ProofingOrderDao proofingOrderDao;
	@Autowired
	MsgNoticeService msgNoticeService;
	@Autowired
	OrderTaskFlowService orderTaskFlowService;
	@Autowired
	ProofingPatternDao proofingPatternDao;
	@Override
	public Order selectById(Long id) {
		return orderDao.selectByPrimaryKey(id);
	}
	@Override
	public List<OrderResult> getAllOrder(OrderQuery orderQuery) {
		// TODO Auto-generated method stub
		orderQuery.setRecourdCount(orderDao.selectOrderTotal(orderQuery));
		return orderDao.selectOrder(orderQuery);
	}
	@Override
	public void saveAssignManager(Long orderId, Integer userId,Long proofingOrderId) {
		Order order = orderDao.selectByPrimaryKey(orderId);
		order.setManager(userId);
		orderDao.updateByPrimaryKey(order);
		/**********************************/
		
		
		MsgNoticeDto msgNoticeDto = new MsgNoticeDto();
		msgNoticeDto.setTitle("新的打样订单");
		ProofingOrder proofingOrder = proofingOrderDao.selectByPrimaryKey(proofingOrderId);
		msgNoticeDto.setContent(customerDao.selectByPrimaryKey(order.getCustomerId().intValue()).getFullname()
								+ "客户的打样订单，请尽快安排工厂，截止时间为"+UfdmDateUtil.dateToString(proofingOrder.getProductionEnddate(), "MM月dd日"));
		msgNoticeDto.setOrderType(OrderTypeEnum.T2.toString());
		msgNoticeDto.setTaskId(proofingOrderId);
		msgNoticeDto.setEnddate(proofingOrder.getProductionEnddate());
		msgNoticeDto.setUserType(0);
		msgNoticeDto.setOrderId(order.getId());
		msgNoticeService.insert(msgNoticeDto,userId);
	}
	@Override
	public void saveAssignManager(Long orderId, Integer userId) {
		Order order = orderDao.selectByPrimaryKey(orderId);
		order.setManager(userId);
		orderDao.updateByPrimaryKey(order);
		
	}

}
